package com.neiquan.backstage.role.imp;

import java.io.Serializable;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neiquan.backstage.common.util.ExtraSpringHibernateTemplate;
import com.neiquan.backstage.pub.bsc.dao.po.Event;
import com.neiquan.backstage.pub.bsc.dao.po.Role;
import com.neiquan.backstage.role.RoleService;

@Service
public class RoleServiceImp implements RoleService{
	private static Class<?> poc = Role.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;
	@Override
	public void add(Role entity) {
		extraSpringHibernateTemplate.getHibernateTemplate().save(entity);
	}
	@Override
	public Role queryById(int id) {
		// TODO Auto-generated method stub
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "roleId", id);
	}
	@Override
	public void updata(Role entity) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().update(entity);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Role> queryAll() {
		// TODO Auto-generated method stub
		return (List<Role>) extraSpringHibernateTemplate.findAll(poc);
	}
	@Override
	public Role queryByName(String name,Integer memberId) {
		// TODO Auto-generated method stub
		List<Role> roles=(List<Role>) extraSpringHibernateTemplate.getHibernateTemplate().find("From Role where name=? and memberId=?", name,memberId);
		if(roles.size()>0){
			return  roles.get(0);
		}
		return null;
		
	}
}
